<?php
namespace Core\Libs\Html;

class Html {
	
	public static function gera($arrCampo, $DBDriver, $projectName, $autoIncrement = false, $fk)
	{
		$readOnly = '';
		$tabela = $arrCampo["Tabela"];
		$campo = $arrCampo["Campo"];
		$projectName = \Core\Libs\Extend\Config::getNamespace($projectName, 1);
		$class = \Core\Libs\Extend\Config::getNamespace($tabela, 1);
		$class = \Core\Libs\Inflexao\Inflexao::_singularizarOuPluralizar($class,'singular', 'caixaAlta', 0);
		
		if($arrCampo["EXTRA"] == "auto_increment")
		{
			$readOnly = "readonly='readonly'";
			if(!$autoIncrement){
				return "";
			}
		}
		
		if($DBDriver == "mysql")
		{
			
		
			if($arrCampo["Tipo_chave"] == "FOREIGN KEY")
			{	
				
				$tabelaRef = $arrCampo["Tabela_Referencia"];
				$classRef = \Core\Libs\Inflexao\Inflexao::_singularizarOuPluralizar($tabelaRef,'singular', 'caixaAlta', 0);
				$classRef = \Core\Libs\Extend\Config::getNamespace($classRef, 1);
				$classRef = str_replace("_", "", $classRef);
						
				$str = "<label>$classRef:</label>";
				$str .= "\t\t\t<select name=\"Model.$projectName.$tabela.$campo\">";
				$str .= "\n\t\t\t<?php";
				$str .= "\n\t\t\tforeach (\$".$classRef."FK as \$item".$classRef."FK){";
				$str .= "?>";
				$str .= "\n\t\t\t\t<option value='<?php echo \$item".$classRef."FK['".$campo."'] ?>'><?php echo \$item".$classRef."FK[\$".$classRef."FK['display']] ?></option>";
				$str .= "\n\t\t\t<?php";
				$str .= "\n\t\t\t}";
				$str .= "\n\t\t\t?>";
				$str .= "\n\t\t\t</select>";
								
			}
			else 
			{
				if(count($fk) > 0 && $arrCampo["Tipo_chave"] == "PRIMARY KEY")
				{
				
					
				 for($i = 0; $i < count($fk); $i++)
				    {
				    	if($fk[$i]["Campo"] == $campo)
						{
							//print_r($campo."-".$tabela);
							//break;
							return "";
						}
				    }
				}
				
				switch ($arrCampo["Tipo"])
				{
				case "char" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" value=\"<?php echo \$".$class."['$campo'] ?>\" $readOnly >";
				 		break;
				 	}
				 case "varchar" :
				 	{
				 		
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" value=\"<?php echo \$".$class."['$campo'] ?>\" $readOnly >";
				 		break;
				 	}
				 case "int" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" value=\"<?php echo \$".$class."['$campo'] ?>\" $readOnly >";
				 		break;
				 	}
				case "Integer" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" $readOnly >";
				 		break;
				 	}
				case "TinyInt" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" $readOnly >";
				 		break;
				 	}
				case "SmallInt" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "MediumInt" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "BigInt" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Float" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "xReal" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Double" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Decimal" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Dec" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Numeric" :
				 	{
				 		$str = "<label>$campo:</label> <input type='text' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Bit" :
				 	{
				 		$str = "<label>$campo:</label> <input type='checkbox' name=\"Model.$projectName.$tabela.$campo\" ><br/>
				 									   <input type='checkbox' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				case "Bool" :
				 	{
				 		$str = "<label>$campo:</label> <input type='checkbox' name=\"Model.$projectName.$tabela.$campo\" ><br/>
				 									   <input type='checkbox' name=\"Model.$projectName.$tabela.$campo\" >";
				 		break;
				 	}
				}
			}
			
		}
		
		//print_r($str);
		//break;
		
		return $str;
	}

}

?>